<?php

namespace IDock\Insurance\LIHI\Response;

use IDock\Http\Response;

class AllLIHIResponse extends Response
{

    public function resolve(): Response
    {
        $body = $this->getBody();
        if (!json_decode($body)) {
            $this->setError('返回数据异常');
            return $this;
        }
        $data = json_decode($body, true);

        if ($this->printer and is_string($this->printer)) {
            $this->printer = new $this->printer;
        }

        $resultCode = $data['result']['resultCode'] ?? '';
        $resultMess = $data['result']['resultMessage'] ?? '';
        $status = $data['result']['status'] ?? '';

        if ($resultCode != '0') {
            $this->setError($resultMess);
            return $this;
        }
        $this->setBody($data);

        return $this;
    }
}
